package com.hz.house.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import com.hz.house.common.ResultBean;
import com.hz.house.common.ResultUtil;
import com.hz.house.exception.ServiceException;

/**
 * 异常抛出后置处理器.处理全局异常
 * @author lfw
 *
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

	private static Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
	@ExceptionHandler(value = Throwable.class)
	public ResultBean defaultErrorHandler(Throwable e) {
		if (e instanceof ServiceException)
			return ResultUtil.fail("服务繁忙,请稍后再试");
		e.printStackTrace();
		log.error("请求异常",e);
		return ResultUtil.serverError();
	}
	
}
